<?php

class ridersModel extends commonModel {

    public function __construct() {
        $this->initialDB();
    }


    public function uploadDir($file_name) {
        $file_dir = Data::$_pic_path.$file_name;
        $doc_dir = FileUpload::setUploaddir('index.php', $file_dir); // C:/wamp/www/sample/
        $dir = $doc_dir . $file_dir;
        return $dir;
    }


    public function cityData(){
        $sql="SELECT c1.code as code1, c1.fullname as fullname1, c2.code as code2, c2.fullname as fullname2, c3.code as code3, c3.fullname as fullname3 FROM `area`  c1 
                RIGHT JOIN `area`  c2 ON c2.parent_code=c1.code 
                RIGHT JOIN `area`  c3 ON c3.parent_code=c2.code
                WHERE c1.is_parent=1 AND c1.parent_code=1 ";
        $this->db->setStatement($sql);

        $result= $this->db->execute();
        $result=$this->getArray($result);
        return $result;

    }

    public function getNewsCount(){
        $sql = "SELECT * FROM news  WHERE (status = 9 OR status = 7 OR status = 3) AND riders_tel = '{$_SESSION['riders']['tel']}' AND ico = 1 AND isdeleted = 0";
        $res = $this->getAny($sql);
        if (!empty($res)) {
            while ($row = mysqli_fetch_array($res, MYSQLI_ASSOC)) {
                $rsp_list[] = $row;
            }
        }
        $newsCount = count($rsp_list);
        return $newsCount;
    }


    public function couponshareexecute($express_id,$SessionTel)
    {

        $result = $this->db->couponshareexecute($express_id,$SessionTel);

        return $result;
    }

    public function checkRiders($name,$nickName){
        $sql = "SELECT id FROM riders  WHERE (name = '$name' OR username = '$nickName') AND isdeleted = 0";
        $res = $this->getAny($sql);
        $rsp_list = [];
        if (!empty($res)) {
            while ($row = mysqli_fetch_array($res, MYSQLI_ASSOC)) {
                $rsp_list[] = $row;
            }
        }
        if($rsp_list && count($rsp_list) > 0){
            return true;
        }else{
            return false;
        }
    }
}
